//@param base.site_url() 鍏ㄥ眬鍙橀噺
/**
 * 鍊掕鏃�
 * @Author   King
 * @DateTime 2015-10-08T13:21:32+0800
 */
function countdown(time, target, text) {
    $(target).addClass('btn-gray').removeClass('btn-green');
    var timer = setInterval(function() {
        time--;
        $(target).text("閲嶆柊鍙戦€�(" + time + ")");
        if (time <= 0) {
            clearInterval(timer);
            $(target).text(text).addClass('btn-green').removeClass('btn-gray');
        }
    }, 1000);
}

/**
 * 妫€鏌ョ姸鎬侊紱
 * @Author   King
 * @DateTime 2015-11-20T10:10:40+0800
 */
function checkStatus(that){
    if(userHandler.isLogin()){
        window.location.href = $(that).attr('data-url');
    }else{
        userHandler.login({
            callback:function(){
                window.location.href = $(that).attr('data-url');
            }
        });
    }
}
/**
 * 鎰忚鍙嶉
 * @Author   King
 * @DateTime 2015-12-22T13:51:27+0800
 */
function suggest(){
    $.post(base.site_url()+'client/memMng/memInfo/getUserMobile',null,function(ret){
        var $popup = dialog({
            title:'鎰忚鍙嶉',
            padding:0,
            width:340,
            content:template('suggest_tpl',{fu_mobile:ret.data})
        }).showModal();

        //琛ㄥ崟楠岃瘉
        artForm.validate('suggest_form',userHandler.getValidateRules(),function(data,e){
            data.url = window.location.href;
            $.post(base.site_url()+'client/service/suggestion/sendSuggestion', {data: JSON.stringify(data)},function(ret){
                if(ret.code == 0){
                    $popup.remove();
                    base.alertMsg({
                        text:"鎻愪氦鎴愬姛锛岃阿璋紒",
                        offset:{
                            x:'0px',
                            y:'160px'
                        }
                    })
                }else{
                    base.alertMsg({
                        text:ret.message
                    })
                }
            },'json');

        });
    },'json');

    //灏忎簬ie10 placeholder
    try{
        if(lt_ie10){
            $('#suggest_form input').placeholder({isUseSpan:true});
        }
    }catch(ex){
        console.log(ex);
    }
}



/**
 *寰俊鐧诲綍鐩稿叧閫昏緫
 */
var userHandler = function(){
    var $login_holder = $("#login_holder");

    var __validateRules = {
        rules: {
            fu_mobile: {
                required: true,
                range: [13000000000,20000000000]
            },
            fu_password: {
                required: true,
                minlength: 6,
                maxlength: 16
            },
            pic_code: "required",
            vcode:"required",
            fu_vcode:"required",
            newpwd:{
                required: true,
                minlength: 6,
                maxlength: 16
            },
            content:"required"
        },
        messages: {
            fu_mobile: {
                required: "璇疯緭鍏ユ墜鏈哄彿鐮�",
                range: "璇疯緭鍏ユ纭殑鎵嬫満鍙风爜"
            },
            fu_password: {
                required: "璇疯緭鍏ュ瘑鐮�",
                minlength: "瀵嗙爜闀垮害涓嶈兘灏忎簬6浣�",
                maxlength: "瀵嗙爜闀垮害涓嶈兘澶т簬16浣�"
            },
            pic_code: "璇疯緭鍏ラ獙璇佺爜",
            vcode:"璇疯緭鍏ョ煭淇￠獙璇佺爜",
            fu_vcode:"璇疯緭鍏ョ煭淇￠獙璇佺爜",
            newpwd: {
                required: "璇疯緭鍏ュ瘑鐮�",
                minlength: "瀵嗙爜闀垮害涓嶈兘灏忎簬6浣�",
                maxlength: "瀵嗙爜闀垮害涓嶈兘澶т簬16浣�"
            },
            content:"璇疯緭鍏ュ弽棣堝唴瀹�"
        }
    };

    var __getLoginHtml = function(fu_mobile){
        var html = '<div class="drop-wrap">'+
            '<a href="javascript:void(0);"><span class="icon_user"></span><span>'+fu_mobile+'</span></a>'+
            '<ul class="arrow-top nav-down-wrap">'+
            '<li><a href="/user" target="_blank">涓汉涓績</a></li>'+
            '<li><a href="javascript:void(0);" onclick="userHandler.logout();">閫€鍑虹櫥褰�</a></li>'+
            '</ul>'+
            '</div>';
        return html;
    };
    //鐧诲綍寮圭獥鍐呭锛�
    var __getLoginTemplate = function(ret,fu_mobile){
        var fu_mobile = fu_mobile || '';
        var loginTemplate = '<div class="account-login-wrap" id="accountLoginWrap" style="height:100%;">'
            +'<ul class="login-tab">'
            +'<li class="col-md-6" onclick="userHandler.quickLogin();">鎵嬫満楠岃瘉鐮佺櫥褰�</li>'
            +'<li class="col-md-6 on">璐﹀彿瀵嗙爜鐧诲綍</li>'
            +'</ul>'
            +'<form action="" method="post" id="accountLoginForm">'
            +	'<div class="fm-wrap">'
            +   	'<div class="input-wrap"><i class="icon-tel"></i><input type="text" name="fu_mobile" value="'+fu_mobile+'" placeholder="鎵嬫満鍙�"></div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="input-wrap"><i class="icon-pwd"></i><input type="password" name="fu_password" placeholder="瀵嗙爜"></div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="input-wrap"><i class="icon-pcode"></i><input type="text" name="pic_code" placeholder="楠岃瘉鐮�"><div class="pic-wrap" id="pic_code_wrap" onclick="userHandler.getPicCode(this)">'+ret.data+'</div></div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="switch-wrap">'
            +			'<div class="col-md-6"><label><input type="checkbox" id="login_remmber_status">璁颁綇鎴�</label></div>'
            +			'<div class="col-md-6 t-r link" onclick="userHandler.forget();">蹇樿瀵嗙爜</div>'
            +   		'<div id="messages_box" class="messages-box"></div>'
            +       '</div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="button-wrap">'
            +			'<input type="submit" value="鐧诲綍">'
            +			'<div class="c-green right-label"><span class="c-gray">杩樻病鏈夎处鍙凤紵</span><span class="link" onclick="userHandler.register();">椹笂娉ㄥ唽</span></div>'
            +		'</div>'
            +	'</div>'
            // +   '<div class="decorative"><span>浣跨敤绗笁鏂硅处鍙风櫥褰�</span></div>'
            // +   '<div class="third-part">'
            // +		'<span class="part part-wechat" onclick="userHandler.wechatLogin();"></span>'
            // +		'<span class="part part-qq"></span>'
            // +		'<span class="part part-blog"></span>'
            // +   '</div>'
            +'</form>'
            +'</div>';

        return loginTemplate;
    };



    //鐧诲綍寮圭獥鍐呭锛�
    var __getQuickLoginTemplate = function(ret,fu_mobile){
        var fu_mobile = fu_mobile || '';
        var template = 	'<div class="quick-login-wrap" id="quickLoginWrap" style="height:100%;">'
            +'<ul class="login-tab">'
            +'<li class="col-md-6 on">鎵嬫満楠岃瘉鐮佺櫥褰�</li>'
            +'<li class="col-md-6" onclick="userHandler.login();">璐﹀彿瀵嗙爜鐧诲綍</li>'
            +'</ul>'
            +'<form action="" method="post" id="quickLoginForm">'
            +'<div class="mod-item" id="mod_register">'
            +	'<div class="fm-wrap">'
            +   	'<div class="input-wrap"><i class="icon-tel"></i><input type="text" name="fu_mobile" placeholder="鎵嬫満鍙�" value="'+fu_mobile+'"><div class="sms-button sms-button-error" id="sms_btn">鑾峰彇楠岃瘉鐮�</div></div>'
            +	'</div>'
            +   '<div id="picCode" class="fm-wrap" style="display:none;">'
            +   	'<div class="switch-wrap" style="margin-bottom:0;">'
            +   		'<div class="input-wrap"><i class="icon-pcode"></i><input type="text" class="not-post" id="loginPicCode" placeholder="璇疯緭鍏ュ浘鐗囬獙璇佺爜"><div class="pic-wrap" id="Lpic_code_wrap" onclick="userHandler.getPicCode(this)">'+ret.data+'</div></div>'
            +       '</div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="input-wrap"><i class="icon-pcode"></i><input type="text" name="vcode" placeholder="鐭俊楠岃瘉鐮�"></div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="switch-wrap">'
            +   		'<div id="messages_box" class="messages-box"></div>'
            +       '</div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="input-wrap"><input type="submit" value="鐧诲綍"></div>'
            +	'</div>'
            +'</div>'
            +'<div class="mod-item mod-item-validate" id="mod_register_validate">'
            +   '<div class="fm-wrap" style="margin-top:30px;">'
            +   	'<div class="input-wrap"><i class="icon-pcode"></i><input type="text" class="not-post" id="quickLoginPicCode" placeholder="璇疯緭鍏ュ浘鐗囬獙璇佺爜"><div class="pic-wrap" id="pic_code_wrap" onclick="userHandler.getPicCode(this)">'+ret.data+'</div></div>'
            +	'</div>'
            +   '<div class="fm-wrap">'
            +   	'<div class="button-wrap">'
            +			'<div class="fu-button" id="get_vcode_btn">纭畾</div>'
            +		'</div>'
            +	'</div>'
            +'</div>'
            +'</form>'
            +'</div>';
        return template;
    };

    //娉ㄥ唽寮圭獥鍐呭锛�
    var __getRegisterTemplate = function(ret,mobile){
        var fu_mobile = mobile || '';
        var registerTemplate = '<form action="" method="post" id="register_form">'+
            '<div class="mod-item" id="mod_register">'+
            '<div class="fm-wrap">'+
            '<div class="input-wrap"><i class="icon-tel"></i><input type="text" name="fu_mobile" placeholder="鎵嬫満鍙�" value="'+fu_mobile+'"><div class="sms-button sms-button-error" id="sms_btn">鑾峰彇楠岃瘉鐮�</div></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="input-wrap"><i class="icon-pcode"></i><input type="text" name="vcode" placeholder="鐭俊楠岃瘉鐮�"></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="input-wrap"><i class="icon-pwd"></i><input type="password" name="fu_password" placeholder="璁剧疆瀵嗙爜"></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="switch-wrap">'+
            '<div id="messages_box" class="messages-box"></div>'+
            '</div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="button-wrap">'+
            '<input type="submit" value="娉ㄥ唽">'+
            '<div class="c-green right-label"><span class="c-gray">宸叉湁璐﹀彿锛�</span><span class="link" onclick="userHandler.login();">鐩存帴鐧诲綍</span></div>'+
            '<p style="margin:10px 0;" class="c-gray">娉ㄥ唽鍗宠涓哄悓鎰�<a class="link c-gray" href="https://www.yizhaofang.cn/protocol" target="_blank">銆婃槗鎵炬埧鏈嶅姟鍗忚銆�</a></p>'+
            '</div>'+
            '</div>'+
            '</div>'+
            '<div class="mod-item mod-item-validate" id="mod_register_validate">'+
            '<div class="fm-wrap" style="margin-top:60px;">'+
            '<div class="input-wrap"><i class="icon-pcode"></i><input type="text" name="pic_code" placeholder="璇疯緭鍏ュ浘鐗囬獙璇佺爜"><div class="pic-wrap" id="pic_code_wrap" onclick="userHandler.getPicCode(this)">'+ret.data+'</div></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="button-wrap">'+
            '<div class="fu-button" id="get_vcode_btn">纭畾</div>'+
            '</div>'+
            '</div>'+
            '</div>'+
            '</form>';

        return registerTemplate;
    };
    //娉ㄥ唽寮圭獥鍐呭锛�
    var __getForgetTemplate = function(ret,mobile){
        var fu_mobile = mobile || '';
        var forgetTemplate = '<form action="" method="post" id="forgetForm">'+
            '<div class="mod-item" id="mod_register">'+
            '<div class="fm-wrap">'+
            '<div class="input-wrap"><i class="icon-tel"></i><input type="text" name="fu_mobile" placeholder="鎵嬫満鍙�" value="'+fu_mobile+'"><div class="sms-button sms-button-error" id="sms_btn">鑾峰彇楠岃瘉鐮�</div></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="input-wrap"><i class="icon-pcode"></i><input type="text" name="fu_vcode" placeholder="鐭俊楠岃瘉鐮�"></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="input-wrap"><i class="icon-pwd"></i><input type="password" name="newpwd" placeholder="璁剧疆瀵嗙爜"></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="switch-wrap">'+
            '<div id="messages_box" class="messages-box"></div>'+
            '</div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="input-wrap"><input type="submit" value="閲嶇疆瀵嗙爜"></div>'+
            '</div>'+
            '</div>'+
            '<div class="mod-item mod-item-validate" id="mod_register_validate">'+
            '<div class="fm-wrap" style="margin-top:60px;">'+
            '<div class="input-wrap"><i class="icon-pcode"></i><input type="text" name="pic_code" placeholder="璇疯緭鍏ュ浘鐗囬獙璇佺爜"><div class="pic-wrap" id="pic_code_wrap" onclick="userHandler.getPicCode(this)">'+ret.data+'</div></div>'+
            '</div>'+
            '<div class="fm-wrap">'+
            '<div class="button-wrap">'+
            '<div class="fu-button" id="get_vcode_btn">纭畾</div>'+
            '</div>'+
            '</div>'+
            '</div>'+
            '</form>';
        return forgetTemplate;
    };

    //鑾峰彇鍥剧墖楠岃瘉鐮侊紱
    var __getPicCode = function(callback){
        $.post(base.site_url('client/memMng/memLogin/rand_create'),null, function(ret) {
            callback(ret);
        }, 'json');
    };

    //鍊掕鏃讹紱
    var __countDown = function(time,target,text){
        target.addClass('sms-button-error');
        var timer = setInterval(function() {
            time--;
            target.text("閲嶆柊鍙戦€�(" + time + ")");
            if (time <= 0) {
                clearInterval(timer);
                target.text(text).removeClass('sms-button-error');
            }
        }, 1000);
    };


    //澶勭悊娉ㄥ唽銆佺櫥褰曢棶棰橈紱
    (function(){
        var fu_name = $.cookie('js_fu_mobile');
        if(fu_name){
            $login_holder.html(__getLoginHtml(fu_name));
        }else{
            $login_holder.html('<a class="drop-btn" href="javascript:void(0);" onclick="userHandler.quickLogin();">娉ㄥ唽/鐧诲綍</a>');
        }
    })();

    return {
        //妫€鏌ユ槸鍚︾櫥褰曪紱
        isLogin:function(){
            return ($.cookie('js_fu_mobile')) && true || false;
        },
        //鍊掕鏃讹紱
        countdown:function(time,target,text){
            __countDown(time,target,text);
        },
        //鑾峰彇楠岃瘉瑙勫垯;
        getValidateRules:function(){
            return __validateRules;
        },
        //寰俊鐧诲綍锛�
        wechatLogin:function(){
            var data = {
                url:window.location.pathname
            };
            $.post(base.site_url('/client/memMng/memWechatLogin/getWechatLoginUrl'),data,function(ret){
                if(ret.code === 0){
                    window.location.href = ret.data;
                }else{
                    base.alertMsg({
                        text:ret.message
                    });
                }
            },'json');
        },
        //閫€鍑虹櫥褰�
        logout:function(){
            var data = {
                url: window.location.href
            };
            $.post(base.site_url('client/memMng/memLogin/logout'), data, function(ret) {
                if(ret.code === 0){
                    window.location.reload();
                }
            }, 'json');
        },

        //鐧诲綍鎴愬姛
        loginSuccess:function(){
            var html = __getLoginHtml($.cookie("js_fu_mobile"));


            $login_holder.html(html);
            //鍏抽棴寮圭獥
            if(dialog.get('registerPopup')){
                dialog.get('registerPopup').remove();
            }
            if(dialog.get('loginPopup')){
                dialog.get('loginPopup').remove();
            }
            if(dialog.get('quickLoginPopup')){
                dialog.get('quickLoginPopup').remove();
            }
        },

        getPicCode:function(that){
            __getPicCode(function(ret){

                if(ret.data){
                    $(that).html(ret.data);
                }

            });
        },

        //鐧诲綍寮圭獥锛�
        login:function(arg){
            arg = arg || {};

            dialog.get('registerPopup') && dialog.get('registerPopup').remove();
            dialog.get('quickLoginPopup') && dialog.get('quickLoginPopup').remove();

            __getPicCode(function(ret){
                if(ret.code === 0){
                    dialog({
                        title:'鐢ㄦ埛鐧诲綍',
                        id:'loginPopup',
                        padding:0,
                        width:400,
                        height:360,
                        quickClose: true,
                        skin:'user-popup',
                        innerHTML:'<div i="dialog">'+
                        '<div  i="body" class="user-popup-body"><div i="content" class="user-popup-content"></div></div>'+
                        '<div class="user-popup-footer" i="footer"><div i="statusbar" class="ui-dialog-statusbar"></div><div i="button"></div></div>' +
                        '</div>',
                        content:__getLoginTemplate(ret,arg && arg.fu_mobile)
                    }).showModal();

                    var $html = $("#accountLoginWrap");
                    //澶勭悊琛ㄥ崟锛�
                    $html.find('#accountLoginForm').validate({
                        rules:__validateRules.rules,
                        messages:__validateRules.messages,
                        errorLabelContainer:$html.find("#messages_box"),
                        submitHandler: function(e) {
                            //璁颁綇鎴戯紱
                            if($(e).find('#login_remmber_status').prop('checked')){
                                $.cookie('savefu','yes', { path: '/', expires:30,domain:'zufun.cn' }); //璁剧疆cookie
                            }else{
                                $.cookie('savefu', '', { expires: -1 }); // 鍒犻櫎 cookie
                            }

                            var data = artForm.getData(e);
                            data.fu_password = md5(data.fu_password);

                            if(base.button_loading(e)){
                                $.post(base.site_url('client/memMng/memLogin/loginByMobile'), {data: JSON.stringify(data)}, function(ret) {
                                    if (ret.code === 0) {
                                        if(typeof arg.callback == 'function'){
                                            arg.callback();
                                        }else{
                                            window.location.reload();
                                        }
                                    }else{
                                        base.alertMsg({
                                            text:ret.message
                                        });
                                        $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                                        base.reset_button(e,'鐧诲綍');
                                    }
                                }, 'json');
                            }

                            return false;
                        }
                    });


                    //灏忎簬ie10 placeholder
                    try{
                        if(lt_ie10){
                            $html.find('input').placeholder({isUseSpan:true});
                        }
                    }catch(ex){
                        console.log(ex);
                    }
                }

            });
        },
        quickLogin:function(arg){
            var arg = arg || {};
            dialog.get('registerPopup') && dialog.get('registerPopup').remove();
            dialog.get('loginPopup') && dialog.get('loginPopup').remove();

            __getPicCode(function(ret){

                if(ret.code === 0){
                    dialog({
                        id:'quickLoginPopup',
                        quickClose: true,
                        padding:0,
                        width:400,
                        height:290,
                        skin:'user-popup',
                        innerHTML:'<div i="dialog">'
                        +           '<div  i="body" class="user-popup-body"><div i="content" class="user-popup-content"></div></div>'
                        +           '<div class="user-popup-footer" i="footer"><div i="statusbar" class="ui-dialog-statusbar"></div><div i="button"></div></div>'
                        +'</div>',
                        content:__getQuickLoginTemplate(ret,arg && arg.fu_mobile)
                    }).showModal();

                    $html = $("#quickLoginWrap");

                    //澶勭悊琛ㄥ崟锛�
                    $html.find('#quickLoginForm').validate({
                        rules:__validateRules.rules,
                        messages:__validateRules.messages,
                        errorLabelContainer:$html.find("#messages_box"),
                        debug:true,
                        submitHandler: function(e) {

                            var data = artForm.getData(e);
                            data.pic_code=$html.find('#loginPicCode').val();
                            if(base.button_loading(e)){
                                $.post(base.site_url('client/memMng/memLogin/registerMemberByMoble'), {data: JSON.stringify(data)}, function(ret) {
                                    if (ret.code == 0) {
                                        userHandler.loginSuccess();
                                    }else if(ret.code =="ERR_PICCODE"){
                                        $('#picCode').css('display','block');
                                        $('.user-popup-content').css('height','335');
                                        $html.find('#loginPicCode').val('');
                                        $html.find("#Lpic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                                        base.reset_button(e,'鐧诲綍');
                                    }else{
                                        base.alertMsg({
                                            text:ret.message,
                                            offset:{
                                                y:'120px'
                                            }
                                        });
                                        $html.find("#Lpic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                                        $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                                        base.reset_button(e,'鐧诲綍');
                                    }
                                }, 'json');
                            }

                            return false;
                        }
                    });

                    $html.find('input[name="fu_mobile"]').bind('input propertychange',function(){
                        if(this.value.length == 11 && $(this).parent().find("#sms_btn").text() == "鑾峰彇楠岃瘉鐮�"){
                            $(this).parent().find("#sms_btn").removeClass('sms-button-error');
                        }else{
                            $(this).parent().find("#sms_btn").addClass('sms-button-error');
                        }
                    });

                    //鍒囨崲鍒拌緭鍏ュ浘鐗囬獙璇佺爜锛�
                    $html.find('#sms_btn').click(function(){
                        var fu_mobile=$html.find('input[name="fu_mobile"]').val();
                        fu_mobile=fu_mobile.replace(/[^0-9]*/g,"");
                        $html.find('input[name="fu_mobile"]').val(fu_mobile);
                        if($html.find('input[name="fu_mobile"]').valid() && !$(this).hasClass('sms-button-error')){

                            $html.find("#mod_register").animate({left:'-400px'});
                            $html.find("#mod_register_validate").animate({left:'0px'});
                            $html.find('input[name="pic_code"]').val('');
                            $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱

                        }
                    });

                    //鑾峰彇楠岃瘉鐮侊紱
                    $html.find('#get_vcode_btn').click(function(){
                        var data = {
                            fu_mobile:$html.find('input[name="fu_mobile"]').val(),
                            pic_code:$html.find('#quickLoginPicCode').val(),
                            reg_type:'appoint'
                        };
                        $.post(base.site_url('client/memMng/memLogin/sendSmsForReg'), {data: JSON.stringify(data)}, function(ret) {
                            if(ret.code == 0){
                                $html.find("#mod_register_validate").animate({left:'400px'});
                                $html.find("#mod_register").animate({left:'0px'});
                                __countDown(30,$html.find('#sms_btn'),'鑾峰彇楠岃瘉鐮�');
                                $('#picCode').css('display','none');
                                $('.user-popup-content').css('height','290');
                            }else{
                                base.alertMsg({
                                    text:ret.message,
                                    offset:{
                                        y:'120px'
                                    }
                                });
                                $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                            }
                        }, 'json');
                    });
                }


                //灏忎簬ie10 placeholder
                try{
                    if(lt_ie10){
                        $html.find('input').placeholder({isUseSpan:true});
                    }
                }catch(ex){
                    console.log(ex);
                }

            });
        },
        register:function(arg){
            arg = arg || {};

            if(dialog.get('loginPopup')){
                dialog.get('loginPopup').remove();
            }
            if(dialog.get('quickLoginPopup')){
                dialog.get('quickLoginPopup').remove();
            }

            __getPicCode(function(ret){

                if(ret.code === 0){
                    dialog({
                        title:'鏂扮敤鎴锋敞鍐�',
                        id:'registerPopup',
                        padding:0,
                        width:400,
                        height:290,
                        skin:'user-popup',
                        innerHTML:'<div i="dialog">'+
                        '<div class="user-popup-header"><div i="title" class="user-popup-title"></div><div i="close" class="popup-close icon-close"></div></div>'+
                        '<div  i="body" class="user-popup-body"><div i="content" class="user-popup-content"></div></div>'+
                        '<div class="user-popup-footer" i="footer"><div i="statusbar" class="ui-dialog-statusbar"></div><div i="button"></div></div>'+
                        '</div>',
                        content:__getRegisterTemplate(ret,arg && arg.fu_mobile)
                    }).showModal();

                    var $html = $("#register_form");
                    //澶勭悊琛ㄥ崟锛�
                    $html.validate({
                        rules:__validateRules.rules,
                        messages:__validateRules.messages,
                        errorLabelContainer:$html.find("#messages_box"),
                        submitHandler: function(e) {

                            var data = artForm.getData(e);
                            data.fu_password = md5(data.fu_password);

                            if(base.button_loading(e)){
                                $.post(base.site_url('client/memMng/memLogin/registerMemberByMoble'), {data: JSON.stringify(data)}, function(ret) {
                                    if (ret.code == 0) {
                                        if(typeof arg.callback == 'function'){
                                            arg.callback();
                                        }else{
                                            window.location.reload();
                                        }
                                    }else{
                                        base.alertMsg({
                                            text:ret.message,
                                            offset:{
                                                y:'120px'
                                            }
                                        });
                                        $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                                        base.reset_button(e,'娉ㄥ唽');
                                    }
                                }, 'json');
                            }

                            return false;
                        }
                    });

                    $html.find('input[name="fu_mobile"]').bind('input propertychange',function(){
                        if(this.value.length == 11 && $(this).parent().find("#sms_btn").text() == "鑾峰彇楠岃瘉鐮�"){
                            $(this).parent().find("#sms_btn").removeClass('sms-button-error');
                        }else{
                            $(this).parent().find("#sms_btn").addClass('sms-button-error');
                        }
                    });

                    //鍒囨崲鍒拌緭鍏ュ浘鐗囬獙璇佺爜锛�
                    $html.find('#sms_btn').click(function(){
                        if($html.find('input[name="fu_mobile"]').valid() && !$(this).hasClass('sms-button-error')){

                            $html.find("#mod_register").animate({left:'-400px'});
                            $html.find("#mod_register_validate").animate({left:'0px'});
                            $html.find('input[name="pic_code"]').val('');
                            $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱

                        }
                    });

                    //鑾峰彇楠岃瘉鐮侊紱
                    $html.find('#get_vcode_btn').click(function(){
                        var data = {
                            fu_mobile:$html.find('input[name="fu_mobile"]').val(),
                            pic_code:$html.find('input[name="pic_code"]').val()
                        };
                        $.post(base.site_url('client/memMng/memLogin/sendSmsForReg'), {data: JSON.stringify(data)}, function(ret) {
                            if(ret.code != 2){
                                $html.find("#mod_register_validate").animate({left:'400px'});
                                $html.find("#mod_register").animate({left:'0px'});
                            }
                            if(ret.code == 0){
                                __countDown(30,$html.find('#sms_btn'),'鑾峰彇楠岃瘉鐮�');
                            }else{
                                base.alertMsg({
                                    text:ret.message,
                                    offset:{
                                        y:'120px'
                                    }
                                });
                                $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                            }
                        }, 'json');
                    });
                }


                //灏忎簬ie10 placeholder
                try{
                    if(lt_ie10){
                        $html.find('input').placeholder({isUseSpan:true});
                    }
                }catch(ex){
                    console.log(ex);
                }

            });

        },
        forget:function(){
            dialog.get('quickLogin') && dialog.get('quickLogin').remove();
            dialog.get('loginPopup') && dialog.get('loginPopup').remove();

            __getPicCode(function(ret){

                if(ret.code === 0){
                    dialog({
                        title:'蹇樿瀵嗙爜',
                        id:'forgetPopup',
                        padding:0,
                        width:400,
                        height:260,
                        skin:'user-popup',
                        innerHTML:'<div i="dialog">'+
                        '<div class="user-popup-header"><div i="title" class="user-popup-title"></div><div i="close" class="popup-close icon-close"></div></div>'+
                        '<div  i="body" class="user-popup-body"><div i="content" class="user-popup-content"></div></div>'+
                        '<div class="user-popup-footer" i="footer"><div i="statusbar" class="ui-dialog-statusbar"></div><div i="button"></div></div>'+
                        '</div>',
                        content:__getForgetTemplate(ret)
                    }).showModal();

                    var $html = $("#forgetForm");
                    //澶勭悊琛ㄥ崟锛�
                    $html.validate({
                        rules:__validateRules.rules,
                        messages:__validateRules.messages,
                        errorLabelContainer:$html.find("#messages_box"),
                        submitHandler: function(e) {

                            var data = artForm.getData(e);
                            data.newpwd = md5(data.newpwd);

                            if(base.button_loading(e)){
                                $.post(base.site_url('client/memMng/memLogin/modifyPwdByMobile'), {data: JSON.stringify(data)}, function(ret) {
                                    if (ret.code == 0) {
                                        window.location.reload();
                                    }else{
                                        base.alertMsg({
                                            text:ret.message,
                                            offset:{
                                                y:'120px'
                                            }
                                        });
                                        $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                                        base.reset_button(e,'閲嶇疆瀵嗙爜');
                                    }
                                }, 'json');
                            }

                            return false;
                        }
                    });

                    $html.find('input[name="fu_mobile"]').bind('input propertychange',function(){
                        if(this.value.length == 11 && $(this).parent().find("#sms_btn").text() == "鑾峰彇楠岃瘉鐮�"){
                            $(this).parent().find("#sms_btn").removeClass('sms-button-error');
                        }else{
                            $(this).parent().find("#sms_btn").addClass('sms-button-error');
                        }
                    });


                    //鍒囨崲鍒拌緭鍏ュ浘鐗囬獙璇佺爜锛�
                    $html.find('#sms_btn').click(function(){
                        if($html.find('input[name="fu_mobile"]').valid() && !$(this).hasClass('sms-button-error')){

                            $html.find("#mod_register").animate({left:'-400px'});
                            $html.find("#mod_register_validate").animate({left:'0px'});
                            $html.find('input[name="pic_code"]').val('');
                            $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱

                        }
                    });

                    //鑾峰彇楠岃瘉鐮侊紱
                    $html.find('#get_vcode_btn').click(function(){
                        var data = {
                            fu_mobile:$html.find('input[name="fu_mobile"]').val(),
                            pic_code:$html.find('input[name="pic_code"]').val()
                        };
                        $.post(base.site_url('client/memMng/memLogin/sendSmsForForgetPswd'), {data: JSON.stringify(data)}, function(ret) {
                            if(ret.code == 0){
                                $html.find("#mod_register_validate").animate({left:'400px'});
                                $html.find("#mod_register").animate({left:'0px'});
                                __countDown(30,$html.find('#sms_btn'),'鑾峰彇楠岃瘉鐮�');
                            }else{
                                base.alertMsg({
                                    text:ret.message,
                                    offset:{
                                        y:'120px'
                                    }
                                });
                                $html.find("#pic_code_wrap").click(); //鏇存柊鍥剧墖楠岃瘉鐮侊紱
                            }
                        }, 'json');
                    });
                }


                //灏忎簬ie10 placeholder
                try{
                    if(lt_ie10){
                        $html.find('input').placeholder({isUseSpan:true});
                    }
                }catch(ex){
                    console.log(ex);
                }

            });

        }

    };
}();

function User(){

}
User.prototype.validateRules = {
    rules: {
        fu_mobile: {
            required: true,
            range: [13000000000,20000000000]
        },
        fu_password: {
            required: true,
            minlength: 6,
            maxlength: 16
        },
        pic_code: "required",
        vcode:"required",
        fu_vcode:"required",
        newpwd:{
            required: true,
            minlength: 6,
            maxlength: 16
        },
        content:"required"
    },
    messages: {
        fu_mobile: {
            required: "璇疯緭鍏ユ墜鏈哄彿鐮�",
            range: "璇疯緭鍏ユ纭殑鎵嬫満鍙风爜"
        },
        fu_password: {
            required: "璇疯緭鍏ュ瘑鐮�",
            minlength: "瀵嗙爜闀垮害涓嶈兘灏忎簬6浣�",
            maxlength: "瀵嗙爜闀垮害涓嶈兘澶т簬16浣�"
        },
        pic_code: "璇疯緭鍏ラ獙璇佺爜",
        vcode:"璇疯緭鍏ョ煭淇￠獙璇佺爜",
        fu_vcode:"璇疯緭鍏ョ煭淇￠獙璇佺爜",
        newpwd: {
            required: "璇疯緭鍏ュ瘑鐮�",
            minlength: "瀵嗙爜闀垮害涓嶈兘灏忎簬6浣�",
            maxlength: "瀵嗙爜闀垮害涓嶈兘澶т簬16浣�"
        },
        content:"璇疯緭鍏ュ弽棣堝唴瀹�"
    }
};
User.prototype.getPicCode = function(that){
    $.post(base.site_url('client/memMng/memLogin/rand_create'),null, function(ret) {
        ret.data && that.html(ret.data);
    }, 'json');
};
User.prototype.getVcode = function(data,callback){
    $.post(base.site_url('client/memMng/memLogin/sendSmsForReg'), {data: JSON.stringify(data)}, function(ret) {
        if(callback instanceof Function){
            callback(ret);
        }
    },"json")
};
User.prototype.isLogin = function(){
    return ($.cookie('js_fu_mobile')) && true || false;
};
User.prototype.countDown = function(time,target,text){
    target.addClass('sms-button-error');
    var timer = setInterval(function() {
        time--;
        target.text("閲嶆柊鍙戦€�(" + time + ")");
        if (time <= 0) {
            clearInterval(timer);
            target.text(text).removeClass('sms-button-error');
        }
    }, 1000);
};
User.prototype.judgeButtonStatus = function(form,button,validTarget){
    validTarget.bind("propertychange input",function(){
        if($(this).valid()){
            if(form.valid()){
                button.removeClass("btn-disabled");
            }else{
                if(!button.hasClass("btn-disabled")){
                    button.addClass("btn-disabled");
                }
            }
        }
    });
};
User.prototype.judgeSmsButtonStatus = function(form,button,validateIndex){
    form.find("input[name='fu_mobile']").bind("propertychange input",function(){
        if(this.value.length == 11 && button.text() == "鑾峰彇楠岃瘉鐮�"){
            button.removeClass("sms-button-error");
        }else{
            if(!button.hasClass("sms-button-error")){
                button.addClass("sms-button-error");
            }
        }
    });
};


function UserLogin(target){
    var that = this;
    this.$target      = $(target);
    this.$validTarget = this.$target.find("input[name='pic_code']");
    this.$button      = this.$target.find("input[type='submit']");
    this.$picTarget   = this.$target.find(".pic-wrap").first();
    this.validate();
    this.getPicCode(this.$picTarget);
    this.$picTarget.click(function(){
        that.getPicCode(that.$picTarget);
    });
    this.judgeButtonStatus(this.$target,this.$button,this.$validTarget);
}
UserLogin.prototype = new User();
UserLogin.prototype.validate = function(){
    var that = this;
    that.$target.validate({
        rules:that.validateRules.rules,
        messages:that.validateRules.messages,
        debug:true,
        submitHandler: function(e) {
            var data = artForm.getData(e);
            data.fu_password = md5(data.fu_password);

            console.log(data);
            that.$button.button("loading");
            $.post(base.site_url('client/memMng/memLogin/loginByMobile'), {data: JSON.stringify(data)}, function(ret) {
                if (ret.code === 0) {
                    window.location.reload();
                }else{
                    base.alertMsg({ text:ret.message });
                    that.$button.button("reset");
                    that.getPicCode(that.$picTarget);
                }
            }, 'json');
            return false;
        }
    });

};


function UserQuickLogin(target){
    var that = this;
    var num=0;
    this.$target      = $(target);
    this.$validTarget = this.$target.find("input[name='vcode']");
    this.$button      = this.$target.find("input[type='submit']");
    this.$picTarget   = this.$target.find(".pic-wrap").first();
    this.$picForm     = this.$target.find(".pic-form").first();
    this.$smsButton   = this.$target.find(".sms-button").first();

    this.validate();

    this.judgeSmsButtonStatus(this.$target,this.$smsButton);

    this.judgeButtonStatus(this.$target,this.$button,this.$validTarget);
    this.$picTarget.click();
    this.$picTarget.click(function(){
        that.getPicCode(that.$picTarget);
    });

    this.$smsButton.click(function(){
        num++;
        if(num==1){
            that.getPicCode(that.$picTarget);
        }
        that.getVcodeQuickLogin();
    });

}
UserQuickLogin.prototype = new User();
UserQuickLogin.prototype.getVcodeQuickLogin = function(){
    var that = this;
    if(this.$target.find("input[name='fu_mobile']").valid() && !this.$smsButton.hasClass("sms-button-error")){

        var data = {
            fu_mobile:that.$target.find('input[name="fu_mobile"]').val(),
            pic_code:that.$target.find('input[name="pic_code"]').val(),
            reg_type:'appoint'
        };
        that.getVcode(data,function(ret){
            switch(ret.code){
                case 0:
                    that.countDown(30,that.$smsButton,'鑾峰彇楠岃瘉鐮�');
                    break;
                case 1:
                case 2:
                    base.alertMsg({ text:ret.message });
                    that.getPicCode(that.$picTarget);
                    break;
                case "ERR_PICCODE":
                    base.alertMsg({ text:"璇疯緭鍏ュ浘鐗囬獙璇佺爜" });
                    that.$picForm.show();
                    break;
            }
        });

    }
}
UserQuickLogin.prototype.validate = function(){
    var that = this;
    that.$target.validate({
        rules:that.validateRules.rules,
        messages:that.validateRules.messages,
        debug:true,
        submitHandler: function(e) {
            var data = artForm.getData(e);
            data.pic_code=that.$target.find('input[name="pic_code"]').val();
            that.$button.button("loading");
            $.post(base.site_url('client/memMng/memLogin/registerMemberByMoble'), {data: JSON.stringify(data)}, function(ret) {
                if (ret.code === 0) {
                    // if(that.callback instanceof Function){
                    if(that.$target.attr('id')=='userAppointForm'||that.$target.attr('id')=='userAppointForm2'){
//							new UserAppoint(that.$button);
                        that.callback();
                        that.callback = "";
                    }else{
                        window.location.reload();
                    }
                }else if(ret.code =="ERR_PICCODE"){
                    base.alertMsg({ text:"璇疯緭鍏ュ浘鐗囬獙璇佺爜" });
                    that.$button.button("reset");
                    that.$picForm.show();
                    that.getPicCode(that.$picTarget);
                }else{
                    base.alertMsg({ text:ret.message });
                    that.$button.button("reset");
                    that.getPicCode(that.$picTarget);
                }
            }, 'json');
            return false;
        }
    });

}



function UserForget(target){
    var that = this;
    this.$target      = $(target);
    this.$validTarget = this.$target.find("input[name='fu_password']");
    this.$button      = this.$target.find("input[type='submit']");
    this.$picTarget   = this.$target.find(".pic-wrap").first();
    this.$picForm     = this.$target.find(".pic-form").first();
    this.$smsButton   = this.$target.find(".sms-button").first();


    this.validate();

    this.judgeSmsButtonStatus(this.$target,this.$smsButton);

    this.judgeButtonStatus(this.$target,this.$button,this.$validTarget);

    this.getPicCode(this.$picTarget);
    this.$picTarget.click(function(){
        that.getPicCode(that.$picTarget);
    });

    this.$smsButton.click(function(){
        that.getVcodeForget();
    });
}
UserForget.prototype = new User();
UserForget.prototype.getVcode = function(data,callback){
    $.post(base.site_url('client/memMng/memLogin/sendSmsForForgetPswd'), {data: JSON.stringify(data)}, function(ret) {
        if(callback instanceof Function){
            callback(ret);
        }
    },"json")
}
UserForget.prototype.getVcodeForget = function(){
    var that = this;
    if(this.$target.find("input[name='fu_mobile']").valid() && this.$target.find("input[name='pic_code']").valid()  && !this.$smsButton.hasClass("sms-button-error")){

        var data = {
            fu_mobile:that.$target.find('input[name="fu_mobile"]').val(),
            pic_code:that.$target.find('input[name="pic_code"]').val(),
            reg_type:'appoint'
        };
        that.getVcode(data,function(ret){
            switch(ret.code){
                case 0:
                    that.countDown(30,that.$smsButton,'鑾峰彇楠岃瘉鐮�');
                    break;
                case 1:
                case 2:
                    base.alertMsg({ text:ret.message });
                    that.getPicCode(that.$picTarget);
                    break;
                case "ERR_PICCODE":
                    base.alertMsg({ text:"璇疯緭鍏ュ浘鐗囬獙璇佺爜" });
                    that.$picForm.show();
                    break;
            }
        });

    }
}
UserForget.prototype.validate = function(){
    var that = this;
    that.$target.validate({
        rules:that.validateRules.rules,
        messages:that.validateRules.messages,
        debug:true,
        submitHandler: function(e) {
            var data = artForm.getData(e);
            data.fu_password = md5(data.fu_password);

            console.log(data);
            that.$button.button("loading");
            $.post(base.site_url('client/memMng/memLogin/modifyPwdByMobile'), {data: JSON.stringify(data)}, function(ret) {
                if (ret.code === 0) {
                    window.location.reload();
                }else{
                    base.alertMsg({ text:ret.message });
                    that.$button.button("reset");
                    that.getPicCode(that.$picTarget);
                }
            }, 'json');
            return false;
        }
    });

}


function UserRegister(target){
    var that = this;
    this.$target      = $(target);
    this.$validTarget = this.$target.find("input[name='fu_password']");
    this.$button      = this.$target.find("input[type='submit']");
    this.$picTarget   = this.$target.find(".pic-wrap").first();
    this.$picForm     = this.$target.find(".pic-form").first();
    this.$smsButton   = this.$target.find(".sms-button").first();


    this.validate();

    this.judgeSmsButtonStatus(this.$target,this.$smsButton);

    this.judgeButtonStatus(this.$target,this.$button,this.$validTarget);

    this.$picTarget.click(function(){
        that.getPicCode(that.$picTarget);
    });
    this.$smsButton.click(function(){
        that.getVcodeRegister();
    });
}
UserRegister.prototype = new User();
UserRegister.prototype.getVcodeRegister = function(){
    var that = this;
    if(this.$target.find("input[name='fu_mobile']").valid() && !this.$smsButton.hasClass("sms-button-error")){

        var data = {
            fu_mobile:that.$target.find('input[name="fu_mobile"]').val(),
            pic_code:that.$target.find('input[name="pic_code"]').val(),
            reg_type:'appoint'
        };
        that.getVcode(data,function(ret){
            switch(ret.code){
                case 0:
                    that.countDown(30,that.$smsButton,'鑾峰彇楠岃瘉鐮�');
                    break;
                case 1:
                    base.alertMsg({ text:ret.message });
                    that.getPicCode(that.$picTarget);
                    break;
                case "ERR_PICCODE":
                    base.alertMsg({ text:"璇疯緭鍏ュ浘鐗囬獙璇佺爜" });
                    that.$picForm.show();
                    break;
            }
        });

    }
}
UserRegister.prototype.validate = function(){
    var that = this;
    that.$target.validate({
        rules:that.validateRules.rules,
        messages:that.validateRules.messages,
        debug:true,
        submitHandler: function(e) {
            var data = artForm.getData(e);
            data.fu_password = md5(data.fu_password);

            that.$button.button("loading");
            $.post(base.site_url('client/memMng/memLogin/registerMemberByMoble'), {data: JSON.stringify(data)}, function(ret) {
                if (ret.code === 0){
                    window.location.reload();
                }else{
                    base.alertMsg({ text:ret.message });
                    that.$button.button("reset");
                    that.getPicCode(that.$picTarget);
                }
            }, 'json');
            return false;
        }
    });

}


/*
*================================================
*logout
* ==================================================
*/
function UserLogout(){
    this.logout();
}
UserLogout.prototype = new User();
UserLogout.prototype.logout = function(){
    var data = {
        url: window.location.href
    };
    $.post(base.site_url('client/memMng/memLogin/logout'), data, function(ret) {
        if(ret.code === 0){
            window.location.reload();
        }
    }, 'json');
};
$(function(){
    $(document).on("click","[data-toggle='logout']",function(){
        return new UserLogout();
    });
});



function UserFactory(type,target){
    try{

        switch(type){
            case "login":
                return new UserLogin(target);
                break;
            case "forget":
                return new UserForget(target);
                break;
            case "quickLogin":
                return new UserQuickLogin(target);
                break;
            case "register":
                return new UserRegister(target);
                break;
        }

    }catch(ex){
        console.log(ex);
    }
}

$.fn.login = function(){
    return this.each(function(){
        new UserFactory("login",this);
    });
};


$.fn.quickLogin = function(){
    return this.each(function(){
        new UserFactory("quickLogin",this);
    });
}
$.fn.quickLogin.Contructor = UserQuickLogin;



$.fn.forget = function(){
    return this.each(function(){
        new UserFactory("forget",this);
    });
}


$.fn.register = function(){
    return this.each(function(){
        new UserFactory("register",this);
    });
}


/*
*================================================
*appoint
* ==================================================
*/
function UserAppoint(target){
    var that          = this;
    this.$target      = $(target);
    this.apartment_id = this.$target.attr("data-id"),
        this.fu_mobile    = this.$target.attr("data-mobile"),
        this.apt_type     = this.$target.attr("data-type");
    if(this.isLogin()){
        this.appoint();
    }else{
        if(this.$target.data('href')=='zf'){
            $("#appointModal").modal("show");
        }
        User.prototype.callback = function(){
            that.appoint();
            //澧炲姞棰勭害缁熻
            _hmt.push(['_trackEvent', 'pc', 'appointment', 'zufang']);
        };
    }
}
UserAppoint.prototype = new User();
UserAppoint.prototype.appoint = function(){
    $("#appointModal").modal("hide");
    var that = this;
    //鍏抽棴寮圭獥
    var data = {
        apartment_id:that.apartment_id,
        fu_mobile:that.fu_mobile,
        apt_type:that.apt_type
    };

    var mem_appointment_id=that.$target.data('success');
    if(mem_appointment_id>0){
        that.createUserApptQrcode(mem_appointment_id);
    }else{
        $.post(base.site_url('client/memMng/memAppointment/addAppointment'),data, function(ret) {
            if(ret.code === 3 || ret.code == 4 || ret.code == 5){
                //      	if($("#submit_appointment").length > 0){
                // 	_hmt.push(['_trackEvent', 'pc', 'appointment', 'zufang']);
                // 	recordAppointBtnClicked(true);
                // }
                dialog({
                    title:'棰勭害鎴愬姛',
                    width:500,
                    height:300,
                    padding:0,
                    cancel:function(){
                        window.location.reload();
                        return false;
                    },
                    cancelDisplay:false
                }).showModal();
                that.createUserApptQrcode(ret.data);
            }else if(ret.code == 2){
                base.alertMsg({
                    text:ret.message
                });
                setTimeout(function(){
                    window.location.reload();
                },500);
            }else{
                base.alertMsg({
                    text:ret.message
                });
            }
        }, 'json');
    }
}
UserAppoint.prototype.createUserApptQrcode=function(mem_appointment_id){
    //鑾峰彇浜岀淮鐮�
    var data = {
        mem_appointment_id:mem_appointment_id
    };
    $.post(base.site_url('client/apart/apart/createUserApptQrcode'),data,function(ret){
        if(ret.code === 0){
            dialog({
                title:'棰勭害鎴愬姛',
                width:500,
                height:300,
                padding:0,
                content:'<div class="t-c wx-wrap">'+
                '<div><img src="'+ret.data+'" width="144" height="144" /></div>'+
                '<div class="wx-info">'+
                '<p>鎵撳紑寰俊鎵竴鎵紝鍏虫敞鈥滅鎴跨綉鈥濆井淇″叕浼楀彿</p>'+
                '<p>瀹炴椂鎺ユ敹棰勭害閫氱煡锛�<span class="c-blue">鏌ョ湅鍏瘬鑱旂郴鏂瑰紡</span></p>'+
                '</div>'+
                '</div>',
                cancel:function(){
                    window.location.reload();
                    return false;
                },
                cancelDisplay:false
            }).showModal();
        }
    },'json');
}


$(function(){
    $(document).on("click",'[data-toggle="user:appoint"]',function(e){
        var $this   = $(this);
        var href    = $this.attr('href');
        if ($this.is('a')) e.preventDefault();

        return new UserAppoint($this);
    });
});




(function(){
    var $login_holder = $("#login_holder");
    var __getLoginHtml = function(fu_mobile){
        var html = '<div class="drop-wrap">'
            +	'<a href="javascript:void(0);"><span class="icon_user"></span><span>'+fu_mobile+'</span></a>'
            +  	'<ul class="arrow-top nav-down-wrap">'
            +  	  	'<li><a href="/user" target="_blank">涓汉涓績</a></li>'
            +  	  	'<li><a href="javascript:void(0);" data-toggle="logout">閫€鍑虹櫥褰�</a></li>'
            +  	'</ul>'
        '</div>';
        return html;
    };

    var fu_name = $.cookie('js_fu_mobile');
    if(fu_name){
        $login_holder.html(__getLoginHtml(fu_name));
    }else{
        $login_holder.html('<a href="#loginModal" rel="noffolow" data-toggle="modal" data-target="#loginModal">注册/登录</a>');
    }
})();

//$(window).bind("load", function() {
//  var timeout = setTimeout(function() { $("img.lazy").trigger("sporty") },2000);
//});
$(function(){
//  $("img.lazy").lazyload({
//      event : "sporty"
//  });
    $("img.lazy").lazyload({
        event : "scroll"
    });


    $("#loginForm").login();
    $("#registerForm").register();
    $("#quickLoginForm").quickLogin();
    $("#forgetForm").forget();
    $("#userAppointForm").quickLogin();
    $("#userAppointForm2").quickLogin();

    $('#forgetModal').on('show.bs.modal', function (e) {
        $("#loginModal").modal("hide");
    });
    $("#registerModal").on('show.bs.modal', function (e) {
        $("#loginModal").modal("hide");
    });
    $("#loginModal").on('show.bs.modal', function (e) {
        $("#registerModal").modal("hide");
    });
});